package com.hsav.kcxb.activity;

import android.net.Uri;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.hsav.kcxb.R;
import com.hsav.kcxb.fragment.setting.CacheFragment;
import com.hsav.kcxb.fragment.setting.NightFragment;
import com.hsav.kcxb.fragment.setting.SettingFragment;

public class SettingActivity extends BaseActivity implements SettingFragment.OnFragmentInteractionListener {

    public static final int TYPE_CACHE = 1;
    public static final int TYPE_FEEDBACK = 2;
    public static final int TYPE_NIGHT = 3;

    private FragmentManager fragmentManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aty_setting_layout);
        fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();

        SettingFragment settingFragment = SettingFragment.newInstance("","");
        transaction.add(R.id.linear_setting_container,settingFragment);
        transaction.commit();
    }

    @Override
    public void onFragmentInteraction(Uri uri) {

    }

    @Override
    public void gotoOtherPage(int type) {
        if(type == TYPE_CACHE){
            CacheFragment cacheFragment = new CacheFragment();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.linear_setting_container,cacheFragment);
            if(fragmentTransaction.isAddToBackStackAllowed()){
                fragmentTransaction.addToBackStack(String.valueOf(type));
            }
            fragmentTransaction.commit();
        }else if(type == TYPE_NIGHT){
            NightFragment nightFragment = new NightFragment();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.linear_setting_container,nightFragment);
            fragmentTransaction.addToBackStack(String.valueOf(TYPE_NIGHT));
            fragmentTransaction.commit();
        }
    }
}
